package com.quectel.util.common;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class StreamUtils {

    private static final int EOF = -1;


    public static long copy(InputStream in, OutputStream os) throws IOException {
        try (BufferedInputStream bis = new BufferedInputStream(in);) {
            int len = 0;
            long size = 0;
            byte[] buffer = new byte[4096];
            while ((len = bis.read(buffer)) != EOF) {
                os.write(buffer, 0, len);
                size += len;
            }
            os.flush();
            return size;
        } finally {
            os.close();
        }

    }
}
